package c.j.a.d.b.j;

import android.text.TextUtils;
import android.util.SparseArray;
import c.j.a.d.b.e.n;
import com.ss.android.socialbase.downloader.g.b;
import com.ss.android.socialbase.downloader.g.c;
import java.util.ArrayList;
import java.util.List;

/* compiled from: DownloadCache */
public class p implements n {
    public final SparseArray<c> a = new SparseArray();
    public final SparseArray<List<b>> b = new SparseArray();

    public c C(int i, long j) {
        c b = b(i);
        if (b != null) {
            b.p(j, false);
            b.b0(-2);
        }
        return b;
    }

    public void E(b bVar) {
    }

    public c I(int i, long j, String str, String str2) {
        c b = b(i);
        if (b != null) {
            b.T = j;
            b.E = str;
            if (TextUtils.isEmpty(b.b) && !TextUtils.isEmpty(str2)) {
                b.b = str2;
            }
            b.b0(3);
        }
        return b;
    }

    public c O(int i, long j) {
        c b = b(i);
        if (b != null) {
            b.p(j, false);
            b.b0(-1);
            b.V = false;
        }
        return b;
    }

    public List<c> a(String str) {
        ArrayList arrayList = new ArrayList();
        synchronized (this.a) {
            try {
                int size = this.a.size();
                for (int i = 0; i < size; i++) {
                    c cVar = (c) this.a.valueAt(i);
                    if (str != null && str.equals(cVar.d)) {
                        arrayList.add(cVar);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return arrayList;
    }

    public c b(int i) {
        c cVar;
        synchronized (this.a) {
            try {
                cVar = (c) this.a.get(i);
            } catch (Exception e) {
                e.printStackTrace();
                cVar = null;
            }
        }
        return cVar;
    }

    public List<c> c(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        synchronized (this.a) {
            if (this.a.size() == 0) {
                return null;
            }
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < this.a.size(); i++) {
                c cVar = (c) this.a.get(this.a.keyAt(i));
                if (cVar != null && !TextUtils.isEmpty(cVar.u) && cVar.u.equals(str) && cVar.o0() == -3) {
                    arrayList.add(cVar);
                }
            }
            return arrayList;
        }
    }

    public boolean c() {
        return false;
    }

    public synchronized void d(int i) {
        this.b.remove(i);
    }

    public void d(int i, List<b> list) {
    }

    public boolean d() {
        return false;
    }

    public c e(int i) {
        c b = b(i);
        if (b != null) {
            b.b0(2);
        }
        return b;
    }

    public boolean f(int i) {
        l(i);
        d(i);
        return true;
    }

    public c g(int i) {
        c b = b(i);
        if (b != null) {
            b.b0(5);
            b.V = false;
        }
        return b;
    }

    public c h(int i) {
        c b = b(i);
        if (b != null) {
            b.b0(1);
        }
        return b;
    }

    public void i(int i, List<b> list) {
        if (list != null) {
            d(i);
            for (b bVar : list) {
                if (bVar != null) {
                    f(bVar);
                    if (bVar.j()) {
                        for (b f : bVar.i) {
                            f(f);
                        }
                    }
                }
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:45:0x0060 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x005d  */
    public java.util.List<com.ss.android.socialbase.downloader.g.c> j(java.lang.String r8) {
        /*
        r7 = this;
        r0 = android.text.TextUtils.isEmpty(r8);
        r1 = 0;
        if (r0 == 0) goto L_0x0008;
    L_0x0007:
        return r1;
    L_0x0008:
        r0 = r7.a;
        monitor-enter(r0);
        r2 = r7.a;	 Catch:{ all -> 0x0065 }
        r2 = r2.size();	 Catch:{ all -> 0x0065 }
        if (r2 != 0) goto L_0x0015;
    L_0x0013:
        monitor-exit(r0);	 Catch:{ all -> 0x0065 }
        return r1;
    L_0x0015:
        r1 = new java.util.ArrayList;	 Catch:{ all -> 0x0065 }
        r1.<init>();	 Catch:{ all -> 0x0065 }
        r2 = 0;
        r3 = 0;
    L_0x001c:
        r4 = r7.a;	 Catch:{ all -> 0x0065 }
        r4 = r4.size();	 Catch:{ all -> 0x0065 }
        if (r3 >= r4) goto L_0x0063;
    L_0x0024:
        r4 = r7.a;	 Catch:{ all -> 0x0065 }
        r4 = r4.keyAt(r3);	 Catch:{ all -> 0x0065 }
        r5 = r7.a;	 Catch:{ all -> 0x0065 }
        r4 = r5.get(r4);	 Catch:{ all -> 0x0065 }
        r4 = (com.ss.android.socialbase.downloader.g.c) r4;	 Catch:{ all -> 0x0065 }
        if (r4 == 0) goto L_0x0060;
    L_0x0034:
        r5 = r4.u;	 Catch:{ all -> 0x0065 }
        r5 = android.text.TextUtils.isEmpty(r5);	 Catch:{ all -> 0x0065 }
        if (r5 != 0) goto L_0x0060;
    L_0x003c:
        r5 = r4.u;	 Catch:{ all -> 0x0065 }
        r5 = r5.equals(r8);	 Catch:{ all -> 0x0065 }
        if (r5 == 0) goto L_0x0060;
    L_0x0044:
        r5 = r4.o0();	 Catch:{ all -> 0x0065 }
        r6 = -1;
        if (r5 == r6) goto L_0x005a;
    L_0x004b:
        r6 = -2;
        if (r5 == r6) goto L_0x005a;
    L_0x004e:
        r6 = -7;
        if (r5 == r6) goto L_0x005a;
    L_0x0051:
        r6 = -4;
        if (r5 == r6) goto L_0x005a;
    L_0x0054:
        r6 = -5;
        if (r5 != r6) goto L_0x0058;
    L_0x0057:
        goto L_0x005a;
    L_0x0058:
        r5 = 0;
        goto L_0x005b;
    L_0x005a:
        r5 = 1;
    L_0x005b:
        if (r5 == 0) goto L_0x0060;
    L_0x005d:
        r1.add(r4);	 Catch:{ all -> 0x0065 }
    L_0x0060:
        r3 = r3 + 1;
        goto L_0x001c;
    L_0x0063:
        monitor-exit(r0);	 Catch:{ all -> 0x0065 }
        return r1;
    L_0x0065:
        r8 = move-exception;
        monitor-exit(r0);	 Catch:{ all -> 0x0065 }
        throw r8;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.p.j(java.lang.String):java.util.List");
    }

    public void k(int i, int i2, long j) {
        List<b> list = (List) this.b.get(i);
        if (list != null) {
            for (b bVar : list) {
                if (bVar != null && bVar.f == i2) {
                    bVar.f(j);
                    break;
                }
            }
        }
    }

    public boolean l(int i) {
        synchronized (this.a) {
            this.a.remove(i);
        }
        return true;
    }

    public void m(int i, int i2, int i3, long j) {
        List<b> list = (List) this.b.get(i);
        if (list != null) {
            for (b bVar : list) {
                if (bVar != null && bVar.f == i3 && !bVar.j()) {
                    list = bVar.i;
                    if (list != null) {
                        for (b bVar2 : list) {
                            if (bVar2 != null && bVar2.f == i2) {
                                bVar2.f(j);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    public void n(int i, int i2, int i3, int i4) {
    }

    public c o(int i) {
        c b = b(i);
        if (b != null) {
            b.b0(-7);
        }
        return b;
    }

    public c t(int i, long j) {
        c b = b(i);
        if (b != null) {
            b.p(j, false);
            b.b0(-3);
            b.V = false;
            b.W = false;
        }
        return b;
    }

    public synchronized void f(b bVar) {
        int i = bVar.a;
        List list = (List) this.b.get(i);
        if (list == null) {
            list = new ArrayList();
            this.b.put(i, list);
        }
        list.add(bVar);
    }

    /* JADX WARNING: Removed duplicated region for block: B:39:0x0057 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0054  */
    public java.util.List<com.ss.android.socialbase.downloader.g.c> b(java.lang.String r8) {
        /*
        r7 = this;
        r0 = android.text.TextUtils.isEmpty(r8);
        r1 = 0;
        if (r0 == 0) goto L_0x0008;
    L_0x0007:
        return r1;
    L_0x0008:
        r0 = r7.a;
        monitor-enter(r0);
        r2 = r7.a;	 Catch:{ all -> 0x005c }
        r2 = r2.size();	 Catch:{ all -> 0x005c }
        if (r2 != 0) goto L_0x0015;
    L_0x0013:
        monitor-exit(r0);	 Catch:{ all -> 0x005c }
        return r1;
    L_0x0015:
        r1 = new java.util.ArrayList;	 Catch:{ all -> 0x005c }
        r1.<init>();	 Catch:{ all -> 0x005c }
        r2 = 0;
        r3 = 0;
    L_0x001c:
        r4 = r7.a;	 Catch:{ all -> 0x005c }
        r4 = r4.size();	 Catch:{ all -> 0x005c }
        if (r3 >= r4) goto L_0x005a;
    L_0x0024:
        r4 = r7.a;	 Catch:{ all -> 0x005c }
        r4 = r4.keyAt(r3);	 Catch:{ all -> 0x005c }
        r5 = r7.a;	 Catch:{ all -> 0x005c }
        r4 = r5.get(r4);	 Catch:{ all -> 0x005c }
        r4 = (com.ss.android.socialbase.downloader.g.c) r4;	 Catch:{ all -> 0x005c }
        if (r4 == 0) goto L_0x0057;
    L_0x0034:
        r5 = r4.u;	 Catch:{ all -> 0x005c }
        r5 = android.text.TextUtils.isEmpty(r5);	 Catch:{ all -> 0x005c }
        if (r5 != 0) goto L_0x0057;
    L_0x003c:
        r5 = r4.u;	 Catch:{ all -> 0x005c }
        r5 = r5.equals(r8);	 Catch:{ all -> 0x005c }
        if (r5 == 0) goto L_0x0057;
    L_0x0044:
        r5 = r4.o0();	 Catch:{ all -> 0x005c }
        r6 = -1;
        if (r5 == r6) goto L_0x0051;
    L_0x004b:
        r6 = -7;
        if (r5 != r6) goto L_0x004f;
    L_0x004e:
        goto L_0x0051;
    L_0x004f:
        r5 = 0;
        goto L_0x0052;
    L_0x0051:
        r5 = 1;
    L_0x0052:
        if (r5 == 0) goto L_0x0057;
    L_0x0054:
        r1.add(r4);	 Catch:{ all -> 0x005c }
    L_0x0057:
        r3 = r3 + 1;
        goto L_0x001c;
    L_0x005a:
        monitor-exit(r0);	 Catch:{ all -> 0x005c }
        return r1;
    L_0x005c:
        r8 = move-exception;
        monitor-exit(r0);	 Catch:{ all -> 0x005c }
        throw r8;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.p.b(java.lang.String):java.util.List");
    }

    public c a(int i, int i2) {
        c b = b(i);
        if (b != null) {
            b.R = i2;
        }
        return b;
    }

    public boolean a(c cVar) {
        boolean z = true;
        if (cVar == null) {
            return true;
        }
        synchronized (this.a) {
            if (this.a.get(cVar.g0()) == null) {
                z = false;
            }
            this.a.put(cVar.g0(), cVar);
        }
        return z;
    }

    public c a(int i, long j) {
        c b = b(i);
        if (b != null) {
            boolean z = false;
            b.p(j, false);
            if (!(b.o0() == -3 || b.o0() == -2)) {
                int o0 = b.o0();
                if (o0 == -1 || o0 == -7) {
                    z = true;
                }
                if (!(z || b.o0() == -4)) {
                    b.b0(4);
                }
            }
        }
        return b;
    }

    public List<b> c(int i) {
        return (List) this.b.get(i);
    }

    public void b() {
        synchronized (this.a) {
            this.a.clear();
            this.b.clear();
        }
    }

    public void b(c cVar) {
        a(cVar);
    }
}
